﻿using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
    /// <summary>
    /// Specifies the directory to find the referenced assemblies in.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class AssemblyBuilderDirectoryAttribute : Attribute
    {
        private readonly string wellKnownDirectoryName;

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="AssemblyBuilderDirectoryAttribute"/> class.
        /// </summary>
        /// <param name="wellKnownDirectoryName">Name of the well known directory.</param>
        public AssemblyBuilderDirectoryAttribute(string wellKnownDirectoryName)
        {
            this.wellKnownDirectoryName = wellKnownDirectoryName;
        }
        #endregion Constructors

        #region Public Properties
        /// <summary>
        /// Gets the name of the well known directory.
        /// </summary>
        /// <value>The name of the well known directory.</value>
        public string WellKnownDirectoryName
        {
            get { return this.wellKnownDirectoryName; }
        }
        #endregion Public Properties

        #region Public Methods
        public static string GetDirectoryName(Type type)
        {
            var directoryAttribute = (AssemblyBuilderDirectoryAttribute)Attribute.GetCustomAttribute(
                type,
                typeof(AssemblyBuilderDirectoryAttribute));

            return directoryAttribute == null ? type.FullName : directoryAttribute.WellKnownDirectoryName;
        }
        #endregion Public Methods
    }
}